package com.beloteGame.domain;

import lombok.Data;

import com.beloteGame.Enums.Color;

/**
 * <br>
 * <br>
 * Copyright : Copyright (c) 2012. <br>
 * <br>
 * Société : BeloteFree
 * 
 * @author PITH
 * @version $Revision: 1.0 $ - $Date: 22 mai 2012 $
 */
@Data
public class CardImpl implements Card {

    private int value;
    private Color color;

    /**
     * Constructeur.
     */
    public CardImpl() {
    }

    @Override
    public int compareTo(Card arg0) {
        int result = 0;
        if (arg0 == null) { // if the card is null, we throw an exception
            throw new NullPointerException();
        } else if (this.isTrumpCard() && !arg0.isTrumpCard()) {
            result = 1; // if the card is a trump and not the other, the card is greatter
        } else if (!this.isTrumpCard() && arg0.isTrumpCard()) {
            result = -1; // if the card is not a trump and the other is, the card is lower
        } else {
            result = this.getValue() - arg0.getValue(); // otherwise we compare the card values
        }
        return result;
    }

    @Override
    public void setValue(final int cardValue) throws Exception {
        // If the value of the card lower than 1 or greatter than 13, it throws Exception.
        if (cardValue < 1 || cardValue > 13) {
            throw new Exception() {
                /** serialVersionUID. */
                private static final long serialVersionUID = 1L;

                @Override
                public String getMessage() {
                    return cardValue + " is an invalid parameter for the value of the card.";
                }
            };
        }
        this.value = cardValue;
    }

    @Override
    public boolean isTrumpCard() {
        // TODO implement the way to know how to get the trump color.
        return false;
    }

}
